const fs = require('fs');
const dirname = 'C:\\Users\\Gentle\\Desktop\\map文件对比\\新'
const files = [];
const arr = recursion(dirname, files)

// console.log(files);

function recursion(file, filearr = []) {
    const isFile = fs.statSync(file).isFile();
    if (isFile) {
        filearr.push(file)
    } else if (fs.statSync(file).isDirectory()) {
        fs.readdirSync(file).forEach(subfile => {
            recursion(file + '\\' + subfile, filearr)
        })
    }
}

const newdir = 'C:\\Users\\Gentle\\Desktop\\map文件对比\\qwh_meeting_新';
files.filter(file => file.endsWith('.Mapper.xml')).forEach(item => {
    let filename = item.substring(item.lastIndexOf('\\') + 1);
    const fs = require('fs');
    try {
        fs.copyFileSync(item, newdir + "\\" + filename);
        console.log(filename + '同步复制完成');
    } catch (err) {
        console.error(filename + '同步复制失败:', err);
    }
})
